<template>
  <el-cascader :value="value" :props="defaultProp" :options="options" @change="handleChange" />
</template>

<script>
import { department } from '@/api/department'
import { ArrayToTree } from '@/utils/index'
export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      options: [],
      //   value: [],
      defaultProp: {
        value: 'id',
        label: 'name'
      }
    }
  },
  created() {
    this.department()
  },
  methods: {
    async department() {
      const res = await department()
      // console.log(res.data)
      this.options = ArrayToTree(res.data, 0)
      // console.log(this.options)
    },
    handleChange(value) {
      // console.log(value)
      const id = value[value.length - 1]
      // console.log(id)
      this.$emit('input', id)
    }
  }
}
</script>

<style>

</style>
